package com.example.myDesignPatterns.结构型模式.装饰者模式Decorator;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


public abstract class Profit extends Garnish {
    private float cost; // Add the cost field here
//        super(fastFood, fastFood.getPrice(), fastFood.getDesc(), cost);
    //           炒饭对象       炒饭价格                 炒饭名称        成本
    public Profit(FastFood baseItem, float price, String desc, float cost) {
        super(baseItem, price, desc);
        this.cost = cost;
    }


    @Override // 实现从 FastFood 继承来的抽象方法
    public float calculateCost() {
        float price1 = getBaseItem().getPrice();
        float v = price1 - cost;
        return v;
    }


    public float getPrice() {
        float v = getBaseItem().getPrice();
        return  v;
    }
//
//    public float setPrice() {
//        float price1 =super.calculateCost();
//        return  price1;
//    }


    public String getDesc() {
        String desc = getBaseItem().getDesc();
        return  desc;
    }


    public float calculateProfit() {
        return getPrice() - cost;
    }

}

class OnlyFried extends Profit {

    /**
     * @param fastFood
     * @param cost     成本费
     */
    public OnlyFried(FastFood fastFood, float cost) {
        super(fastFood, fastFood.getPrice(), fastFood.getDesc(), cost);
    }
}

class GarnishAndFried extends Profit {

    public GarnishAndFried(FastFood fastFood, float ... values) {
        super(fastFood, fastFood.getPrice(), fastFood.getDesc(),  calculateTotal(values) );
    }

    //数组
    private static float calculateTotal(float[] values) {
        float total = 0;
        //语法名称 for循环
        //语法作用 遍历数组

        //元素
        for (float value : values) {
            total += value;
        }
        return total;
    }
}